package com.heima.wemedia.controller.v1;

import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dtos.WmNewsDto;
import com.heima.model.wemedia.dtos.WmNewsFailDto;
import com.heima.model.wemedia.dtos.WmNewsPageReqDto;
import com.heima.model.wemedia.pojos.WmSensitive;
import com.heima.wemedia.service.WmNewsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/api/v1/news")
public class WmNewsController {


    @Autowired
    private WmNewsService wmNewsService;

    @PostMapping("/auth_pass")
    public ResponseResult authPass(@RequestBody WmNewsDto dto) {
        log.info("文章审核通过;{}", dto);
        return wmNewsService.authPass(dto);
    }

    @PostMapping("/auth_fail")
    public ResponseResult authFail(@RequestBody WmNewsFailDto dto) {
        log.info("文章审核驳回;{}", dto);
        return wmNewsService.authFail(dto);
    }

    @PostMapping("/list")
    public ResponseResult findAll(@RequestBody WmNewsPageReqDto dto){

        return  wmNewsService.findAll(dto);
    }
    @GetMapping("/one_vo/{id}")
    public ResponseResult getOneVo(@PathVariable("id") Integer id){
        log.info("查看单个文章: {}",id);
        return ResponseResult.okResult(wmNewsService.getById(id));
    }
    @PostMapping("/list_vo")
    public ResponseResult list_vo(@RequestBody WmNewsPageReqDto dto){
        log.info("人工审核文章列表查询: {}",dto);

        return  wmNewsService.findList(dto);
    }

    @PostMapping("/submit")
    public ResponseResult submitNews(@RequestBody WmNewsDto dto){
        log.info("发布文章或保存草稿: {}",dto);
        return  wmNewsService.submitNews(dto);
    }

    @PostMapping("/down_or_up")
    public ResponseResult downOrUp(@RequestBody WmNewsDto dto){
        log.info("文章上下架:{}",dto);
        return wmNewsService.downOrUp(dto);
    }

    @GetMapping ("/one/{id}")
    public ResponseResult getOne(@PathVariable("id") Integer id){
        log.info("查看单个文章: {}",id);
        return ResponseResult.okResult(wmNewsService.getById(id));
    }




}